#include <iostream>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;

int cost(int a, int b);
int dp[5][5][2],t,n,now,step;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        now = 0;
        memset(dp,INF,sizeof(dp));
        dp[0][0][0] = 0;

        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&step);
            for(int i=0;i<5;i++)
            {
                for(int j=0;j<5;j++)
                {
                    if(dp[i][j][now] != INF)
                    {
                        if(j != step)
                        {
                            dp[step][j][now^1] = min(dp[step][j][now^1],dp[i][j][now]+cost(i,step));
                        }
                        if(i != step)
                        {
                            dp[i][step][now^1] = min(dp[i][step][now^1],dp[i][j][now]+cost(j,step));
                        }
                    }
                    dp[i][j][now] = INF;
                }
            }
            now^=1;
        }
        int res = INF;
        for(int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                res = min(res,dp[i][j][now]);
            }
        }
        printf("%d\n",res);
    }
    return 0;
}

int cost(int a, int b)
{
    int res;
    if(a == 0)
    {
        res = 2;
    }
    else if(abs(a-b) == 2)
    {
        res = 4;
    }
    else if(abs(a-b) == 1 || (a==1&&b==4) || (a==4&&b==1))
    {
        res = 3;
    }
    else if(a == b)
    {
        res = 1;
    }
    else
    {
        res = 2;
    }
    return res;
}
